package string.nowcoder.easy;

import java.util.Scanner;

/**
 * @author Stark
 * @description 统计回文
 * @date 2022/4/23 10:57
 **/
public class CountPalindrome {
    static int choice = 2;
    public static void main(String[] args){
        //旧方法，没有合理使用String自带的方法
        if(choice == 1) {
            Scanner scanner = new Scanner(System.in);
            while (scanner.hasNext()) {
                String strA = scanner.nextLine();
                String strB = scanner.nextLine();
                int count = 0;
                int start = 0, mid = 0, end = strA.length();
                for (; mid <= end; mid++) {
                    String judgeStr = strA.substring(start, mid) + strB + strA.substring(mid, end);
                    count += judge(judgeStr);
                }
                System.out.println(count);
            }
        }

        //使用StringBuilder的方法
        if(choice == 2){
            Scanner scanner = new Scanner(System.in);
            while(scanner.hasNextLine()){
                String strA = scanner.nextLine();
                String strB = scanner.nextLine();
                int count = 0;
                int length = strA.length();
                //这里要相等于length
                for (int i = 0; i <= length; i++) {
                    //每次都要重新使用一个字符串,否则会将原始字符串改变
                    //插入,逆置,删除等方法都是String没有的
                    StringBuilder sbA = new StringBuilder(strA);
                    sbA.insert(i,strB);
                    //注意这里，不能直接StringBuilder str5 = str.reverse();
                    //因为这样str本身又变了。
                    StringBuilder sbARe = new StringBuilder(sbA);
                    sbARe.reverse();
                    if(sbA.toString().equals(sbARe.toString()))
                        count++;
                }
                System.out.println(count);
            }
        }
    }

    private static int judge(String str) {
        int start = 0;
        int end = str.length() - 1;
        while(start < end){
            char chS = str.charAt(start);
            char chE = str.charAt(end);
            if(chS != chE)
                return 0;
            start++;
            end--;
        }
        return 1;
    }
}
